package com.bdqn.demo.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.security.core.Authentication;

import java.util.Date;

public class JwtUtils {


    public static String token(Authentication authentication) {

        return Jwts.builder()
                .setSubject(authentication.getName())
                .setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000 * 24))
                .signWith(SignatureAlgorithm.HS256, "bdqn")
                .compact();
    }

    public static Claims parse(String token) {
        Claims claims = Jwts.parser()
                .setSigningKey("bdqn")
                .parseClaimsJws(token)
                .getBody();
        return claims;
    }
}
